package com.qf.device.controller;

import com.qf.device.entity.Device;
import com.qf.device.service.DeviceService;
import com.qf.product.dto.PageDto;
import com.qf.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.qf.vo.R;


/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author wxh
 * @since 2023-10-27
 */
@RestController
@RequestMapping("/device")
@CrossOrigin
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

//    @PreAuthorize("hasAuthority('设备列表')")
    @PostMapping("page")
    public PageResult page(@RequestBody PageDto<Device> pageDto){
        PageResult<Device> page = deviceService.page(pageDto);
        return page;
    }

//    @PreAuthorize("hasAuthority('设备添加')")
    @PostMapping("add")
    public R add(@RequestBody Device device) {

        return deviceService.insertDevice(device);
    }

//    @PreAuthorize("hasAuthority('设备更新')")
    @PostMapping("/update")
    public R update(@RequestBody Device device) {
        deviceService.updateById(device);
        return R.ok("更新成功");
    }

//    @PreAuthorize("hasAuthority('设备删除')")
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id) {
        deviceService.removeById(id);
        return R.ok("删除成功");
    }


}
